package com.fxsh168.server.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fxsh168.server.R;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.entitys.ThreeFen;
import com.fxsh168.server.interfaces.Constant;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

public class SoldCenterActivity extends BaseActivity implements View.OnClickListener {

    private String token, mPhone;
    LinearLayout liMyYao, liMyTwo, liMyThree;
    TextView teFenOne;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_income1);
        liMyTwo = (LinearLayout) findViewById(R.id.liMyTwo);
        liMyThree = (LinearLayout) findViewById(R.id.liMyThree);
        TextView teFenTwo = (TextView) findViewById(R.id.teFenTwo);
        TextView teFenThree = (TextView) findViewById(R.id.teFenThree);

        teFenOne = (TextView) findViewById(R.id.teFenOne);
        liMyYao = (LinearLayout) findViewById(R.id.liMyYao);
        SharedPreferences sp = getSharedPreferences(Constant.LOGINCLASS, MODE_PRIVATE);
        mPhone = sp.getString("mPhone", "");
        token = sp.getString("token", "");
        liMyYao.setOnClickListener(this);
        liMyTwo.setOnClickListener(this);
        liMyThree.setOnClickListener(this);
        if (!TextUtils.isEmpty(token)) {
            soldMoney();  //分销中心
        } else {
            jumpActivity(LoginActivity.class);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.liMyYao:
                jumpActivity(MyYaoActivity.class);
                break;
            case R.id.liMyTwo:
                jumpActivity(MyTwoFenActivity.class);
                break;
            case R.id.liMyThree:
                jumpActivity(MyThreeFenActivity.class);
                break;

        }
    }

    //   分销中心
    public void soldMoney() {
        OkHttpUtils.post().url(Constant.THREEFENXIAO).addParams("account", mPhone).build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("tag", "用户端三级分销数据" + response);
                        ThreeFen threeFen = new Gson().fromJson(response, ThreeFen.class);
                        String code = threeFen.getCode();
                        if (code.equals("200")) {
                            ThreeFen.DataBean data = threeFen.getData();
                            String s = data.getOne();    //一级分销
                            String s1 = data.getTwo();    //二级分销
                            String s2 = data.getThree();   //三级分销
                            teFenOne.setText(s);
                        }
                    }
                });
    }


}
